﻿
using System;
using System.Collections.Generic;
using RenewalProjects.Libraries.Wcf.EasyProxy.Tests.TestData;

namespace RenewalProjects.Libraries.Wcf.EasyProxy.Tests.TestBuilders
{
	public class ManagedTestItemBuilder
	{
		private int _count;
		private List<TestItem> _precreatedItems = new List<TestItem>();

		public ManagedTestItemBuilder()
		{
			DelegateFactory = (() => { _count++; return _precreatedItems[_count - 1]; });
		}

		public ManagedTestItemBuilder Add(TestItem item)
		{
			_precreatedItems.Add(item);
			return this;
		}

		public ManagedTestItemBuilder AddAmount(int amount)
		{
			for(int i = 0; i < amount; i++)
			{
				this.Add(new TestItem());
			}

			return this;
		}

		public Func<TestItem> DelegateFactory { get; private set; }

		public int FactoryCallCount { get { return _count; } }

		public IList<TestItem> PrecreatedItems { get { return _precreatedItems; } }
	}
}
